//
//  TZfindViewCell.m
//  XMLYFM
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 zzl. All rights reserved.
//

#import "TZfindViewCell.h"
#import "TZfindModel.h"
#import "ZTFindDetailViewCell.h"
@interface TZfindViewCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property(nonatomic,retain)UICollectionView *myCollectionView;
@property(nonatomic,retain)NSMutableArray *allmodelarray;
@end

@implementation TZfindViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self creatSubViews];
        self.allmodelarray = [NSMutableArray array];
    }

    return self;
    

}

-(void)creatSubViews
{

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
//    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //设置最小列间距
//    flowLayout.minimumInteritemSpacing = 3;
    flowLayout.minimumLineSpacing = 7;
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    flowLayout.itemSize = CGSizeMake((TZWIDTH - 10),(80));
    self.myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0,TZWIDTH,400) collectionViewLayout:flowLayout];
    self.myCollectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.myCollectionView];
    self.myCollectionView.showsHorizontalScrollIndicator = NO;
    
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    [self.myCollectionView registerClass:[ZTFindDetailViewCell class] forCellWithReuseIdentifier:@"ZTFindDetailViewCell"];
    
    

}


//协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{

    return self.allmodelarray.count;


}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
     TZfindModel *find =  [self.allmodelarray objectAtIndex:indexPath.row];
    static NSString *CellId = @"ZTFindDetailViewCell";
    ZTFindDetailViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellId forIndexPath:indexPath];
    cell.findModel = find;
    
    cell.backgroundColor = [UIColor grayColor];
    return cell;


}



-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.row == 2) {
        
        [self.findDeleget pushtoFindDetail:@"http://www.wemart.cn"];
        
    }
    else if (indexPath.row == 3)
    {
        
            [self.findDeleget pushtoFindDetail:@"http://m.diyring.cc"];
    
    }
}




-(void)setMyDic:(NSMutableDictionary *)myDic
{
    [self.allmodelarray removeAllObjects];
    NSMutableArray *Array = myDic[@"list"];
    for (NSMutableDictionary *dic in Array) {
        TZfindModel *model = [[TZfindModel alloc]init];
        [model setValuesForKeysWithDictionary:dic];
        [self.allmodelarray addObject:model];
    }
    [self.myCollectionView reloadData];
    

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
